//
//  IllustrationController.m
//  Hai
//
//  Created by wangzijian on 16/6/13.
//  Copyright (c) 2016年 wangzijian. All rights reserved.
//

#import "GirlReg2Controller.h"
#import "RegisterController.h"

@interface GirlReg2Controller ()

@end

@implementation GirlReg2Controller{
    NSInteger _buttonIndex;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden=NO;
    [ super viewWillAppear:animated];
}
-(IBAction)next{
    RegisterController *l = [[RegisterController alloc] init];
    [self.navigationController pushViewController:l animated:YES];
}
#pragma mark-点击设置年龄按钮
- (IBAction)tapBirthdayView:(id)sender {
    _buttonIndex = 1;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideDatePickerView)];
    [self.view addGestureRecognizer:tapGesture];
    self.calendarView = [[CalendarView alloc]initWithCurrentDate:[NSDate date]];
    self.calendarView.frame =CGRectMake(0, 0, kScreenWidth, kScreenHeight-164);
    self.calendarView.dateDelegate=self;
    [self.view addSubview:self.calendarView];
    [self.calendarView showDatePickerView];
}
#pragma mark-点击设置经期日期
- (IBAction)tapLastdayView:(id)sender {
    _buttonIndex = 4;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideDatePickerView)];
    [self.view addGestureRecognizer:tapGesture];
    self.calendarView = [[CalendarView alloc]initWithCurrentDate:[NSDate date]];
    self.calendarView.frame =CGRectMake(0, 0, kScreenWidth, kScreenHeight-164);
    self.calendarView.dateDelegate=self;
    [self.view addSubview:self.calendarView];
    [self.calendarView showDatePickerView];
}
- (IBAction)tapPeriodView:(id)sender {
    _buttonIndex = 2;
    DayPickViewController *pickVC = [[DayPickViewController alloc]init];
    [self addChildViewController:pickVC];
    pickVC.dayDataDelegate = self;
    pickVC.view.frame =CGRectMake(0, 0, kScreenWidth, kScreenHeight-64);
    [self.view addSubview:pickVC.view];
    
}
- (IBAction)tapCycleView:(id)sender {
    _buttonIndex = 3;
    DayPickViewController *pickVC = [[DayPickViewController alloc]init];
    [self addChildViewController:pickVC];
    pickVC.dayDataDelegate = self;
    pickVC.view.frame =CGRectMake(0, 0, kScreenWidth, kScreenHeight-64);
    [self.view addSubview:pickVC.view];
    
    
}
#pragma mark - 返回时间代理
- (void)sendDate:(NSDate *)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy年MM月dd日"];
    NSString *strDate = [dateFormatter stringFromDate:date];
    NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    if (_buttonIndex==1) {
        _birthdaylable.text =strDate;
        _birthday=[dateFormatter2 stringFromDate:date];
    }else if (_buttonIndex==4){
        _lastdaylable.text =strDate;
        _lastday=[dateFormatter2 stringFromDate:date];
    }
}
#pragma mark - 返回天数代理
- (void)sendDayData:(NSString * __nullable)dayData dayDataIndex:(NSString * __nullable)dayDataIndex{
    if (_buttonIndex==2) {
        _periodlable.text =dayData;
        _period=dayDataIndex;
    }else if (_buttonIndex==3){
        _cyclelable.text =dayData;
        _cycle=dayDataIndex;
    }
}//点击空白隐藏键盘
-(void)hideDatePickerView{
    [self.calendarView cancelSelectCurrentDate];
}
@end